﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>创建表单</title>
    <style type="text/css">
        .style1
        {
            width: 105px;
        }
        #Text4
        {
            width: 447px;
        }
        #TB_Addr
        {
            width: 450px;
        }
    </style>

    <script language="JavaScript" src="../../Comm/JScript.js" type="text/javascript" ></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet"  type="text/css" />
    <link href="../../../DataUser/Style/table0.css" rel="stylesheet"  type="text/css" />

    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>

    <script type="text/javascript" language="javascript" >
        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            var frmType = GetQueryString("FrmType");
            if (frmType == null || frmType=="" )
                frmType = '1';

            //创建表单类型.
            GenerBindEnumKey("DDL_FrmType", "FrmType", frmType);

            //创建数据源.
            GenerBindEntities("DDL_DBSrc", "BP.Sys.SFDBSrcs", "local");

            var sort = GetQueryString("FK_FrmSort");

            //创建表单树.
            GenerBindEntities("DDL_FrmTree", "BP.WF.Template.SysFormTrees", sort);

            $("#Msg").html("");
            return;

        });

        function FrmTypeChange() {

            var frmType = $("#DDL_FrmType").val();

            document.getElementById("PTableName").innerHTML = "存储表";
            document.getElementById("PTableDesc").innerHTML = "数据要存储到那个表里？<br>默认与表单编号一致，指定的表名，必须是下划线或者字母开头，不能包含特殊字符，否则创建表失败。";

            if (frmType == "7") {
                document.getElementById("PTableName").innerHTML = "请输入实体类名";
                document.getElementById("PTableDesc").innerHTML = "该实体必须是以BP.开头的并且从实体BP.En.Entities上继承下来的. <br>比如:BP.Demo.Resumes";
            }

            if (frmType == "3") {
                document.getElementById("PTableName").innerHTML = "请输入URL";
                document.getElementById("PTableDesc").innerHTML = "请输入嵌入式表单的URL.";
            }

            //              1:拿到select对象： var  myselect=document.getElementById("test");
            //  2：拿到选中项的索引：var index=myselect.selectedIndex ;             // selectedIndex代表的是你所选中项的index
            //  3:拿到选中项options的value：  myselect.options[index].value;
            //  4:拿到选中项options的text：  myselect.options[index].text;

            //   var frmType = document.getElementById("DDL_FrmType");
        }
    </script>
</head>
<body >

<form id="cc">
<table style="width:80%;">
<caption>创建独立表单</caption>

<tr>
<td class="Idx" > 1 </td>
<td > 创建的表单类型</td>
<td> <select name="DDL_FrmType" id="DDL_FrmType"   onchange="FrmTypeChange()" />  </td>
<td>根据自己的业务场景需要选择相应的表单类型. </td>
</tr>

<tr>
<td class="Idx" > 2 </td>
<td > 数据源类型</td>
<td> <select name="DDL_DBSrc" id="DDL_DBSrc" />  </td>
<td>该表单要创建到那个数据源上？</td>
</tr>

<tr>
<td class="Idx" > 3 </td>
<td > 节点位置</td>
<td> <select name="DDL_FrmTree" id="DDL_FrmTree" />  </td>
<td>保存到表单树的位置。</td>
</tr>

<tr>
<td class="Idx" > 4 </td>
<td > 表单名称</td>
<td><input type="text" id="TB_Name" name="TB_Name" onblur="GenerPinYin()" /> </td>
<td>表单的名称，允许重复，允许多个表单映射到一张表上。</td>
</tr>

<tr>
<td class="Idx" > 5 </td>
<td >表单编号(必须是字母或者下划线组合)</td>
<td><input type="text" id="TB_No" name="TB_No" /> </td>
<td > 
<input id="RB_ZZMM_0" type="radio" name="RB_ZZMM" value="0" checked=true  onclick="GenerPinYin()" /><label for="RB_ZZMM_0" onclick="GenerPinYin()" >全拼</label>
<input id="RB_ZZMM_1" type="radio" name="RB_ZZMM" value="1"  onclick="GenerPinYin()" /><label for="RB_ZZMM_1" onclick="GenerPinYin()" >简拼</label>
</td>
</tr>

<tr>
<td class="Idx" > 6 </td>
<td > <div id="PTableName" >存储表:</div> </td>
<td><input type="text" id="TB_PTable" name="TB_PTable" /> </td>
<td > 

<div id="PTableDesc" >
数据要存储到那个表里？<br>
</div>

</td>
</tr>

<tr>
<td class="Idx" > 7 </td>
<td >  </td>

<td colspan="2">
<input type="button" value="创建" onclick="Save()" id="Btn_Save" />

<script type="text/javascript">

    function GenerPinYin() {

        //是否是全拼.
        var isQuanPin = 0;
        if (document.getElementById("RB_ZZMM_0").checked == true)
            isQuanPin = 1;

        // var name = $('#TB_Nam').val();
        var name = document.getElementById("TB_Name").value;
        if (name == "") {
            return;
        }

        $.ajax({
            type: 'post',
            async: true,
            url: Handler + "?DoType=NewFrmGuide_GenerPinYin&IsQuanPin=" + isQuanPin + "&TB_Name=" + encodeURIComponent(name) + "&m=" + Math.random(),
            dataType: 'html',
            success: function (data) {
                $("#Msg").html("");

                if (data.indexOf('err@') >= 0) {
                    $("#Msg").html("<font color=red>" + data + "</font>");
                    return;
                }

                $('#TB_No').val("CCFrm_"+data);
                $('#TB_PTable').val("CCFrm_" + data);
                return;
            }
        });
    }
    
    function Save() {

        $("#Msg").html("正在创建,请稍后......");

        var name = document.getElementById("TB_Name").value;
        var no = document.getElementById("TB_No").value;
        var pTable = document.getElementById("TB_PTable").value;

        if (name == "" || no == "" || pTable == "") {
            alert('@请输入必填的字段.');
            return;
        }

        var frmData = $("#cc").serialize();

        $.ajax({
            data: frmData,
            type: 'post',
            async: true,
            url: Handler + "?DoType=NewFrmGuide_Create&m=" + Math.random(),
            dataType: 'html',
            success: function (data) {

                if (data.indexOf('err@') >= 0) {
                    $("#Msg").html("<font color=red>" + data + "</font>");
                    return;
                }

                $("#Msg").html("<font color=green>" + data + "</font>");

                data = data.replace('url@', '');
                window.location.href = data;
                return;
            }
        });
    }
</script>

</td>
</tr>
</table>

<div id="Msg"> </div>

</form>

</body>
</html>
